define([ "app", "jquery", "bootstrapJs","md5", "ecb","angularRadial","radial","highcharts","highcharts-ng",
         "directives/DatetimePicker",
         "services/UserService",
         "resources/OrgResource",
		 "resources/UserResource",
		 "resources/MerchantManagementResource",
		 "services/MessageBox",
		 "directives/common/OrgUserPickerConference",
		 "directives/common/OrgTreeView",
		 "services/TipsService",
		 "services/BaseService"
		],
		function(app) {

	var deps = [ "$scope", "$state", "$window",  "$location",
			"$stateParams", "MenuService", "UserService","OrgResource","MerchantManagementResource", "UserResource","MessageBox","TipsService","BaseService"];

	function controller($scope, $state, $window, $location, $stateParams, MenuService, UserService,OrgResource, MerchantManagementResource,UserResource,MessageBox,TipsService,BaseService) {
			
		$scope.currentPage = 1;
        $scope.pages = [];
        $scope.pageSize = 10;
        //$scope.selected=10;
		queryData();
		
		
		function queryData(){
			MerchantManagementResource.queryMerchantList($scope.currentPage,$scope.pageSize,$scope.merchantKey).success(function(data){
				$scope.data = data.list;
				if(data.count % $scope.pageSize == 0){
         			$scope.totalPage=Math.floor(data.count/$scope.pageSize);
        		}else{
        			$scope.totalPage=Math.floor(data.count/$scope.pageSize)+1;
        		}
            });
		}
		
		
		$scope.gotoPage = function (currentNum) {
            $scope.currentPage = currentNum;
            queryData();
        };
        
        $scope.nextPage = function () {
        	if($scope.currentPage<$scope.totalPage){
        		$scope.currentPage++;
        		queryData();
        	}
        };

        $scope.upPage = function () {
        	if($scope.currentPage>1){
        		$scope.currentPage--;
        		queryData();
        	}	
        };
        
        
		$scope.search =function (){
			queryData();
		};
    };
    
    controller.$inject = deps;
    return app.lazy.controller("MerchantManagementController", controller);
});
